//
//  YDYViewController.m
//  GoodsHoster
//
//  Created by apple on 16/2/19.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "YDYViewController.h"

@interface YDYViewController ()

@end

@implementation YDYViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    a=0;
    
    //============
    arry=@[@"引导页1.png",@"引导页2.png",@"引导页3.png"];
    scr.contentSize=CGSizeMake(WIDTH*arry.count, HEIGHT);
    scr.pagingEnabled=YES;
    
    // NSLog(@"%@",self.arry);
    for (int i=0; i<arry.count; i++) {
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH*i, 0, WIDTH, HEIGHT)];
        image.image=[UIImage imageNamed:[arry objectAtIndex:i]];
        
        [scr addSubview:image];
    }
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(WIDTH*(arry.count-1)+WIDTH/2-100, HEIGHT-150, 200, 150)];
    [btn setBackgroundImage:[UIImage imageNamed:@"立即体验@2x"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(logins:) forControlEvents:UIControlEventTouchUpInside];

    [scr addSubview:btn];
    [UserDefault setObject:@"YES" forKey:@"hasLogin"];
    [UserDefault synchronize];
    //=======pagecontrol
    pageCtrl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH/2, HEIGHT-70, 100, 30)];  //创建UIPageControl，位置在屏幕最下方。
    
    pageCtrl.numberOfPages = arry.count;//总的图片页数
    pageCtrl.currentPage = 0; //当前页
    pageCtrl.selected=NO;
    
    
    
    [self.view addSubview:pageCtrl];  //将UIPageControl添加到主界面上。
    // Do any additional setup after loading the view from its nib.
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        
        // iOS 7
        
        [self prefersStatusBarHidden];
        
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}
- (BOOL)prefersStatusBarHidden {
        
        return YES;//隐藏为YES，显示为NO
    }
-(void)logins:(id)sender{
    
 [UIApplication sharedApplication].delegate.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[LoginViewController new]];


}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    //更新UIPageControl的当前页
    CGPoint offset = scrollView.contentOffset;
    CGRect bounds = self.view.frame;//
    [pageCtrl setCurrentPage:offset.x / bounds.size.width];
    a=offset.x/bounds.size.width;
    //    NSLog(@"%f",offset.x / bounds.size.width);
    //    NSLog(@"111");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
